package com.training.java.core.exceptionhandling;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class ExceptionDemo4 {

	public static void main(String[] args) throws IOException {
		ExceptionDemo4 ed4 = new ExceptionDemo4();
          ed4.printToFile();		

	}
	
	public void printToFile() throws IOException
	
	{
		
		FileWriter fileWriter=null;
		PrintWriter out = null;
		try{
			 fileWriter = new FileWriter("d:\\javatrainingbyreenu.txt");
			 out = new PrintWriter(fileWriter);
			
			out.write("I am trying to catch exception in method itself.");
		
		}
		catch(IOException ex)
		{
			ex.printStackTrace();
		}
		
		finally
		{
			if (out!=null)
			{
			out.close();
			}
			if(fileWriter!=null)
			{
				fileWriter.close();
			}
		}
		/*finally
		{
			out.close();
			try{
				fileWriter.close();
			}catch(IOException ex)
			{
				System.out.println("I am inside finally's catch block");
				ex.printStackTrace();
			}
		}*/
	}

}
